package com.aurora.app.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.aurora.app.dao.ThingStoryImageDao;
import com.aurora.app.entity.ThingImage;
import com.aurora.app.entity.ThingStoryImage;
import com.aurora.app.enums.FakeDelete;
import com.aurora.base.dao.BaseDao;
import com.aurora.base.dto.Order;
import com.aurora.base.service.BaseService;
@Service
public class ThingStoryImageService extends BaseService<ThingStoryImage> {
	@Resource
	private ThingStoryImageDao baseDao;
	@Override
	public BaseDao<ThingStoryImage> getBaseDao() {
		// TODO 自动生成的方法存根
		return this.baseDao;
	}
	
	public List<ThingStoryImage> getListByThingStoryId(String ThingStoryId){
		return this.baseDao.list("o.isDelete = 0 and o.thingStory.id = ?", ThingStoryId);
	}
	
	/**
	 * 获取最新创建的那一福图片
	 * @param thingId
	 * @return
	 */
	public ThingStoryImage  getFirstImageByStoryThingId(String ThingStoryId){
		Order order = new Order();
		order.put("createTime", Order.DESC);
		List<ThingStoryImage> imgList =this.baseDao.list(order,0,1,"o.isDelete = ? and o.thingStory.id =? ", FakeDelete.NODELETE,ThingStoryId);
		if(imgList!=null&!imgList.isEmpty()){
			return imgList.get(0);
		}
		return null;
	}
	
	
	/**
	 * 获取最新创建的size张图片
	 * @param thingId
	 * @return
	 */
	public List<ThingStoryImage>  getBeforeImageByStoryThingId(String ThingStoryId,int size){
		Order order = new Order();
		order.put("createTime", Order.DESC);
		List<ThingStoryImage> imgList =this.baseDao.list(order,0,size,"o.isDelete = ? and o.thingStory.id =? ", FakeDelete.NODELETE,ThingStoryId);
		return imgList;
	}

}
